import loginViews from "$v/login";
import { loginRequest } from "$a/admin";
export default  (req, res) => {

    res.render(loginViews())

    //点击登录逻辑
    document.loginForm.loginBtn.onclick = async function(e){
        e.preventDefault();
        const adminNameValue = document.loginForm.adminName.value;
        const passwordValue = document.loginForm.passWord.value;
        //登入请求
        try{
           const loginResult =  await loginRequest({
                adminName : adminNameValue,
                password : passwordValue
            })
            localStorage.setItem("user_token",loginResult.token)
            router.go('/adv/adminList')
        }catch(e){
            alert("登入异常"+ e.message)
        }
    }
}